﻿namespace TrackSystem.Contracts
{
    public class ApiResult<T>
    {
        /// <summary>
        /// 返回代码
        /// </summary>
        public int Code { get; init; }
        /// <summary>
        /// 成功标记
        /// </summary>
        public bool Success { get; init; }
        /// <summary>
        /// 返回信息
        /// </summary>
        public string? Message { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public T? Data { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult<T> Ok(T data, string msg = "Success") => new()
        {
            Code = 200,
            Success = true,
            Message = msg,
            Data = data
        };

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult<T> Ok(string msg = "Success") => new()
        {
            Code = 200,
            Success = true,
            Message = msg,
        };


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ApiResult<T> Fail(string msg, int code = 400) => new()
        {
            Code = code,
            Success = false,
            Message = msg
        };
    }

}
